<template>
  <div>
    <el-container>
      <el-aside width="50%">
        <h1 class="homeTitle">smallFrog 书店</h1>
        <p class="content" v-html="notice"></p>        
      </el-aside>
      <el-main>        
        <div style="width: 600px; margin:auto">
          
          <el-carousel :interval="4000" type="card" height="400px"  autoplay>
            <el-carousel-item  v-for="item in recBooks" :key="item[3]">
              <!-- <h3 class="medium">{{ item }}</h3> -->
                <img @load="img_load" ref='img_ref' :src="item[2]" @click="toBookInfo(item[0])"/>
            </el-carousel-item>
          </el-carousel>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import axios from "axios";
import myapi from "../api";


export default {
  name: "Index",
  data() {
    return {
      notice: "",
      recBooks: [
		[
			"79bbe618-d2f8-4081-b35a-62ebbe938b64",
			"Java基础入门",
			"/productImg/9/0/697a23d6-225a-41a3-8c20-7ab624265ecc.png",
			3
		],
		[
			"3a0196b2-71c1-4d4d-a4e8-d1f875096f00",
			"网管员必备宝典",
			"/productImg/4/3/0270eba2-2b48-48df-956b-0341204384d9.jpg",
			2
		],
		[
			"3cdd01d2-95d4-4077-b512-ff4c3b340d6b",
			"学会宽容",
			"/productImg/6/5/a2da626c-c72d-4972-83de-cf48405c5563.jpg",
			1
		]
	],
      transRecBooks: [],
      img_height:''
    };
  },
  created() {
    axios.post(myapi.notice.url).then((response) => {
      //用户名和密码将转为json传到后台接口
      let res = response.data; //用res承接返回后台的json文件(像使用数组那样)
      console.log(res.data.details);
      if (res.code == 10) {
        //显示登录结果
        this.notice = res.data.details;
      } else {
        this.$message({
									showClose: true,
									message: '获取失败！请稍后重试！',
									type: 'error',
									center: true
								});
        this.notice = "书城没有最新通知！！";
      }
    });


  },
  methods: {  
    img_load(){
				console.log(this.$refs.img_ref[0].height,'img_height')
				this.img_height = this.$refs.img_ref[0].height
				console.log(this.$refs.img_ref[0].width,'img_width')
			},
  filters:{
			add_px(value){
				return value + 'px';
			}
		},

    toBookInfo(id) {
      axios.get(myapi.bookInfo.url+"?id="+id)
      .then(res=>{
        if(res.data.code==10){
          this.$store.state.book=res.data.data; 
          this.$router.push('/bookDetails');        
        }else{
          this.$message({
									showClose: true,
									message: '获取失败！请稍后重试！',
									type: 'error',
									center: true
								});
        }
      })
      .catch(res=>{
        this.$message({
									showClose: true,
									message: '获取失败！请稍后重试！',
									type: 'error',
									center: true
								});
      });      
    },   
  },
};
</script>

<style>
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.homeTitle {
  width: 400px;
  color: #333333;
  font-size: 40px;
  font-weight: 600;
  text-align: left;
  margin-left: 150px;
}
.content {
  width: 400px;
  color: #333333;
  font-size: 18px;
  line-height: 35px;
  text-align: left;
  margin-left: 150px;
}
img{
width: 100%;

}
</style>